#!/bin/bash
REMOTE=$1
SSH_OPTS=" -x -q -o ConnectTimeout=15 -o BatchMode=yes -o StrictHostKeyChecking=no -o LogLevel=fatal"
echo "Removing remote root login for host $REMOTE"
cat <<-EOF | if [ "$REMOTE" != "localhost" ]; then sudo su - saunix -c "ssh $SSH_OPTS $REMOTE \"cat | sudo /bin/bash\""; else cd /tmp; cat | sudo /bin/bash; fi
	cp -rp /etc/ssh/sshd_config{,.`id -un`.`date +'%Y-%m-%d-%H-%M'`}
	cat /etc/ssh/sshd_config | grep -v 'PermitRootLogin' > /tmp/tmpsshd
	echo PermitRootLogin no >> /tmp/tmpsshd && sudo mv /tmp/tmpsshd /etc/ssh/sshd_config
	/usr/bin/chuser rlogin=false root
	kill -HUP \`ps -ef|grep sshd | grep [/]usr/sbin/sshd | tail -1 | awk '{print \$2}'\`
EOF
